import request from '@/utils/request';

// 分页获取个人密码
export function getPwdPage(currentPage, pageSize, searchParam) {
  return request({
    url: '/v1/accounts/page',
    method: 'get',
    params: {
      currentPage,
      pageSize,
      name: searchParam.name === '' ? null : searchParam.name,
      accountTypeId: searchParam.accountTypeId === '' ? null : searchParam.accountTypeId
    }
  });
}
// 分组获取用户所拥有的全部账号
export function getPwdGroup() {
  return request({
    url: '/v1/accounts',
    method: 'get'
  });
}
// 增加一个个人密码
export function addPwd(pwd) {
  return request({
    url: '/v1/accounts',
    method: 'post',
    data: pwd
  });
}
// 修改个人账户
export function updatePwd(id, pwd) {
  return request(
    {
      url: '/v1/accounts/' + id,
      method: 'put',
      data: {
        'id': id,
        'account': pwd.account,
        'accountTypeId': pwd.accountTypeId,
        'name': pwd.name,
        'password': pwd.password,
        'remark': pwd.remark,
        'url': pwd.url
      }
    }
  );
}

export function sharePwd(shareType, id, roleIds) {
  return request(
    {
      url: '/v1/accounts/' + id + '/share',
      method: 'post',
      data: {
        'shareType': shareType,
        'sharedIds': roleIds
      }
    }
  );
}

// 删除个人账户
export function deletePwd(id) {
  return request({
    url: '/v1/accounts/' + id,
    method: 'delete'
  });
}

// 获取个人和系统类型
export function getSysAndUserType() {
  return request({
    url: '/v1/all/account-types',
    method: 'get'
  });
}
// 获取所有个人类型
export function getUserType() {
  return request({
    url: '/v1/account-types',
    method: 'get'
  });
}

export function addUserType(name, remark) {
  return request({
    url: '/v1/account-types',
    method: 'post',
    data: { name, remark }
  });
}

export function updateUserType(id, name, remark) {
  return request({
    url: '/v1/account-types/' + id,
    method: 'put',
    data: {
      id,
      name: name === '' ? null : name,
      remark: remark === '' ? null : remark
    }
  });
}

export function deleteUserType(id) {
  return request({
    url: '/v1/account-types/' + id,
    method: 'delete'
  });
}
